<?php
/**
 * Created by PhpStorm.
 * User: a
 * Date: 2016/6/7
 * Time: 17:32
 */
namespace Admin\Model;
use Think\Model;

class InvestModel extends Model 
{
	protected $trueTableName = 'bypal_invest_project';

	/**
	 * 收益管理列表页数据
	 */
	public function get_invest_list($numSelect,$typeSelect,$markSelect) 
	{
		$select_sql = "select t1.invest_id,t1.invest_title,t1.invest_total_amount,t1.invest_rate,concat(t3.active_time,' 天') active_time,concat(t1.invest_time_limit,' 天') invest_time_limit,t1.invest_number,t1.invest_money,t4.invest_status_name,t1.invest_status_id,t1.invest_type_id 
				from bypal_invest_project t1 
				left join bypal_invest_activetime t3 on t1.active_time_id = t3.active_time_id 
				left join bypal_invest_status t4 on t1.invest_status_id =t4.invest_status_id 
				where 1=1";

		//	搜索查询条件
		if ($numSelect != '') 
		{
			$select_sql .= " and t1.invest_id like '%$numSelect%'";
		}
		if ($typeSelect != '') 
		{
			$select_sql .= " and t1.invest_type_id = '$typeSelect'";
		}
		if ($markSelect != '') 
		{
			$select_sql .= " and t1.invest_status_id = '$markSelect'";
		}

		$select_sql .= " order by invest_id DESC";

		$Model = new \Think\Model();
		$values = $Model->query($select_sql);

		return $values;
	}


	/**
	 * 投资管理详情页数据
	 */
	public function get_invest_detail($invest_id) 
	{
		$select_sql = "select t1.invest_id,t2.invest_type_name,t1.invest_title,invest_total_amount,t3.active_time,t1.invest_time_limit,t1.invest_rate,t1.accepting_bank,t1.remark,t5.repay_name,t1.create_time,t1.invest_number,t1.invest_money,t4.invest_status_name,t1.invest_type_id,count(t6.invest_detail_id) count 
				from bypal_invest_project t1 
				left join bypal_invest_type t2 on t1.invest_type_id=t2.invest_type_id 
				left join bypal_invest_activetime t3 on t1.active_time_id=t3.active_time_id 
				left join bypal_invest_status t4 on t1.invest_status_id=t4.invest_status_id 
				left join bypal_repay_method t5 on t1.repayment_id=t5.repay_id 
				left join bypal_invest_detail t6 on t1.invest_id=t6.invest_id 
				where t1.invest_id=" . $invest_id;
		$Model = new \Think\Model();
		$values = $Model->query($select_sql);

		return $values;
	}

}